/**
 * 
 */
package com.yxt.user.handler;

import com.alibaba.fastjson.JSON;
import com.yxt.common.utils.R;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author jojo
 *
 */
@Component
public class UserAuthenticationEntryPoint extends OAuth2AuthenticationEntryPoint {

	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException authException) throws IOException, ServletException {

//		if(authException instanceof AccessTokenRequiredException) {
//			System.out.println("2. udpate log to 401");
//		}else {
//			System.out.println("2. add log 401");
//		}
//
//		request.setAttribute("logUpdated", "yes");
		//super.commence(request, response, authException);
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/javascript;charset=utf-8");
		response.getWriter().print(JSON.toJSONString(R.error("没有访问权限!")));
	}
	
}
